package com.kws.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kws.common.security.utils.SecurityUtils;
import com.kws.system.domain.QueryInvoiceMessageRq;
import com.kws.system.domain.TbInvoiceMessage;
import com.kws.system.mapper.InvoiceMessageMapper;
import com.kws.system.service.InvoiceMessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <b>InvoiceMessageServiceImpl</b>
 *
 * @description: InvoiceMessageServiceImpl <br>
 * @date: 2024/11/19 16:17 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Service
public class InvoiceMessageServiceImpl extends ServiceImpl<InvoiceMessageMapper,TbInvoiceMessage> implements InvoiceMessageService {
    private static final Logger logger = LoggerFactory.getLogger(InvoiceMessageServiceImpl.class);


    @Override
    public Page<TbInvoiceMessage> queryInvoicePage(QueryInvoiceMessageRq rq) {
        Page<TbInvoiceMessage> page = new Page<>(rq.getPageNum(), rq.getPageSize());
        Page<TbInvoiceMessage> pageInfo = baseMapper.queryInvoicePage(page,rq);
        return pageInfo;
    }

    @Override
    public TbInvoiceMessage queryInvoiceById(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    public boolean deleteInvoiceById(Long id) {
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("id",id);
        updateWrapper.set("enable","0");
        updateWrapper.set("update_user", SecurityUtils.getStringUserId());
        updateWrapper.set("update_time",new Date());
        int update = baseMapper.update(null, updateWrapper);
        if (1 == update){
            return true;
        }
        return false;
    }
}
